package comnet

import "TODecider/src/pb"

type NetV3 struct {
	Id     string
	Origin string
	Nodes  []Node
	Links  []Link
}

type Node struct {
	Ip            string
	RestComputing []float64
	RestStorage   []float64
}

type Link struct {
	NodeFrom string
	NodeTo   string
	Rate     float64
	EsDelay  float64
}

func fromPbComNet(net *pb.ComNet) NetV3 {
	var nodes []Node
	var links []Link
	for _, node := range net.Nodes {
		nodes = append(nodes, Node{
			Ip:            node.Ip,
			RestComputing: node.RestComputing,
			RestStorage:   node.RestStorage,
		})
	}
	for _, link := range net.Links {
		links = append(links, Link{
			NodeFrom: link.NodeFrom,
			NodeTo:   link.NodeTo,
			Rate:     link.Rate,
			EsDelay:  link.EsDelay,
		})
	}
	return NetV3{
		Id:     net.Id,
		Origin: net.Origin,
		Nodes:  nodes,
		Links:  links,
	}
}
